#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

class Solution {
public:
    int longestConsecutive(vector<int>& nums) {
        if (nums.size() == 0) return 0;
        sort(nums.begin(), nums.end());

        vector<int> arr(nums.size());
        arr[0] = nums[0];
        for (int i = 1, k = 1; i < nums.size(); i++)
        {
            if (nums[i] > arr[k - 1])
            {
                arr[k++] = nums[i];
            }
        }

        int max = 0;
        int sum = 1;
        for (int i = 1; i < arr.size(); i++)
        {
            if (arr[i] - arr[i - 1] == 1)
            {
                sum++;
            }
            else
            {
                max = sum < max ? max : sum;
                sum = 1;
            }
        }
        return max < sum ? sum : max;
    }
};

int main()
{
    vector<int> nums = { 4,0,-4,-2,2,5,2,0,-8,-8,-8,-8,-1,7,4,5,5,-4,6,6,-3 };
    Solution().longestConsecutive(nums);

    return 0;
}